package com.wzcl.app.controller;


import com.wzcl.app.model.common.RVO;
import com.wzcl.app.model.dto.UserDto;
import com.wzcl.app.service.RegisterService;
import com.wzcl.app.utils.CheckUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@Log4j2
@RestController
@RequestMapping("/register")
@Api(value = "注册/密码controller", tags = {"注册于密码相关接口"})
public class RegisterController {
    @Resource
    private RegisterService registerService;


    @PostMapping("/captcha")
    @ApiOperation("发送短信验证码")
    public RVO<String> getCode(@RequestBody UserDto userDto) {
        String code = registerService.sendMsg(userDto.getPhone());
        if (StringUtils.isBlank(code)) {
            return RVO.error("您已发送过验证码，请于一分钟后再试");
        }
        return RVO.success("验证码发送成功");
    }

    @PostMapping("/registerUser")
    @ApiOperation(value = "注册")
    public RVO<String> register(@RequestBody UserDto userDto) {
        registerService.registerUser(userDto);
        return RVO.success();
    }

    @ApiOperation("重置密码")
    @PostMapping("/forgetPwd")
    public RVO<String> forgetPwd(@RequestBody UserDto userDto) {
        registerService.forgetPwd(userDto);
        return RVO.success();
    }


}
